<?php
// +--------------------------------------------------------------------------
// | ISDCE [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2017 载攸道 版权所有 <TEL:086-010-57209502>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * [ Pay模块 ]
 */
namespace Pay\Controller;
use Common\Controller\AdminController;

/**
 * 来源设置
 */
class ConfController extends AdminController{
	
	
	/**
	 * 新增来源
	 */
    public function Create(){
		
		if(IS_POST){
			
		
			$m_pay_type = M('pay_type');
			
			
			
			$data = I('');
			
			$data['status'] = 1;
			
			$result = $m_pay_type->add($data);
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
			
				$this->success('新增成功', U('Pay/Conf/Manage'));
			
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置  
			
				$this->error('新增失败');
			
			}
		
		}else{
			
			//页面配置
			$page = array(
				
				'title'=>'新增来源',
				'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
				'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
				'author'=>'YiPHP',
				'robots' => 'all',
			
			);
			
			$this->assign('page',$page);
		
			$this->display();
		}
		
	}
	
	/**
	 * 来源管理
	 */
    public function Manage(){

		//页面配置
		$page = array(
			
			'title'=>'来源管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		
		);
		
		$this->assign('page',$page);
		
		$m_pay_type = M('pay_type');
			
		$map['status'] = 1;
		
		$list = $m_pay_type->where($map)->select();
	
	
		//赋值
		$this->assign('list',$list);
		
		
		$this->display();
	}
	
	/**
	 * 配置管理
	 */
    public function WeiXin(){
		
		if(IS_AJAX){
			
		
			$m_pay_conf = M('pay_conf');
			
			$map['id'] = 1;
			
			
			$data = I('');
			
			
			$result = $m_pay_conf->where($map)->save($data);
			
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
		
	
			$this->ajaxReturn($info);
		
		}else{
			
			common_public()->assign_page('微信支付设置');
		
			$m_pay_conf = M('pay_conf');
			
			$map['id'] = 1; //约定 id=1是微信
			
			$data = $m_pay_conf->where($map)->find();
			
			$this->assign('data',$data);

			$base_url = $_SERVER['SERVER_NAME'];
		
			$this->assign('base_url',$base_url);
		
		
			$this->display();
		}
		
	}
	
	
	/**
	 * 配置管理
	 */
    public function AliPay(){
		
		if(IS_AJAX){
			
		
			$m_pay_conf = M('pay_conf');
			
			$map['id'] = 2;
			
			
			$data = I('');
			
			
			$result = $m_pay_conf->where($map)->save($data);
			
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
		
	
			$this->ajaxReturn($info);
		
		}else{
			
			common_public()->assign_page('支付宝设置');
		
			$m_pay_conf = M('pay_conf');
			
			$map['id'] = 2; //约定 id=2是支付宝
			
			$data = $m_pay_conf->where($map)->find();
			
			$this->assign('data',$data);

			$this->display();
		}
		
	}
}